import Vue from 'vue'
import coMessage from './co-message'

const MessageConstructor = Vue.extend(coMessage)

export const message = (option = {}) => {
  const MessageInstance = new MessageConstructor({
    data () {
      return {
        message: typeof option === 'string' ? option : option.message || '这是一条提示信息!',
        type: typeof option !== 'string' ? `co-message__${option.type}` : 'co-message__info',
        center: typeof option !== 'string' ? `co-message__${option.center}` : `co-message`,
        showClose: typeof option !== 'string' ? `co-message__${option.type}__${option.showClose}` : `co-message__${option.type}`
      }
    }
  })
  MessageInstance.$mount()
  document.body.appendChild(MessageInstance.$el)
}
